package com.rd.student.jiaji.class3.xumingze.code01;

public class Test4 implements Runnable {

    Object obj = new Object();

    int num = 0;

    @Override
    public void run() {
        synchronized (obj) {
            num++;
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "是第" + num + "个进入山洞的人");
        }
    }

    public static void main(String[] args) {
        Test4 hh = new Test4();
        for (int i = 0; i < 10; i++) {
            new Thread(hh, "第" + (i + 1) + "个猿人 ").start();
//        Thread thread = new Thread();
//        thread.start();
//        Thread thread1 = new Thread();
//        thread1.start();
        }
    }
}